import { camelCase } from "../case"
import httpClient from "../httpclient"
import { data } from "../index"

export class ProductSale {
  public id: string
  public name: string
  public imageUrl: string
  public totalQuantity: number
  public totalAmount: number
}

export class ProductQuery {

  private params = {}

  public storeId(storeId: string): ProductQuery {
    this.params["store_id"] = storeId
    return this
  }

  public date(date: string | number): ProductQuery {
    this.params["date"] = date
    return this
  }

  public dateFrom(dateFrom: string | number): ProductQuery {
    this.params["date_from"] = dateFrom
    return this
  }

  public dateTo(dateTo: string | number): ProductQuery {
    this.params["date_to"] = dateTo
    return this
  }
}

export class ProductReportV1 {

  public static createProductQuery() {
    return new ProductQuery()
  }

  public static queryProductSales(query: ProductQuery): Promise<data.PageList<ProductSale>> {
    return httpClient.get("/v1/reports/product-sales", {
      params: query["params"],
    })
      .then(({ data }) => data)
      .then(camelCase)
  }
}

export class ProductRatingQuery {

  private params = {}

  public storeId(storeId: string): ProductRatingQuery {
    this.params["store_id"] = storeId
    return this
  }

  public date(date: string | number): ProductRatingQuery {
    this.params["date"] = date
    return this
  }

  public dateFrom(dateFrom: string | number): ProductRatingQuery {
    this.params["date_from"] = dateFrom
    return this
  }

  public dateTo(dateTo: string | number): ProductRatingQuery {
    this.params["date_to"] = dateTo
    return this
  }
}

export class TotalProductRatings {
  public averageRating: number
}

export class TotalProductRatingCounts {
  public fiveRatingCount: number
  public fourRatingCount: number
  public threeRatingCount: number
  public twoRatingCount: number
  public oneRatingCount: number
}

export class ProductRatingReportV1 {

  public static createProductRatingQuery() {
    return new ProductRatingQuery()
  }

  public static queryTotalProductRatings(query: ProductRatingQuery): Promise<TotalProductRatings> {
    return httpClient.get("/v1/reports/total-product-ratings", {
      params: query["params"],
    })
      .then(({ data }) => data)
      .then(camelCase)
  }

  public static queryTotalProductRatingCounts(query: ProductRatingQuery): Promise<TotalProductRatingCounts> {
    return httpClient.get("/v1/reports/total-product-rating-counts", {
      params: query["params"],
    })
      .then(({ data }) => data)
      .then(camelCase)
  }
}

export class ProductCountQuery {

  private params = {}

  public storeId(storeId: string): ProductCountQuery {
    this.params["store_id"] = storeId
    return this
  }

  public date(date: string | number): ProductCountQuery {
    this.params["date"] = date
    return this
  }

  public dateFrom(dateFrom: string | number): ProductCountQuery {
    this.params["date_from"] = dateFrom
    return this
  }

  public dateTo(dateTo: string | number): ProductCountQuery {
    this.params["date_to"] = dateTo
    return this
  }
}

export class TotalProductCounts {
  public viewCount: number
  public addedCount: number
  public placedCount: number
  public paidCount: number
  public completedCount: number
}


export class ProductCountReportV1 {

  public static createProductCountQuery() {
    return new ProductCountQuery()
  }

  public static queryTotalProductCounts(query: ProductCountQuery): Promise<TotalProductCounts> {
    return httpClient.get("/v1/reports/total-product-counts", {
      params: query["params"],
    })
      .then(({ data }) => data)
      .then(camelCase)
  }
}

